<?php

namespace app\common\business;

use app\common\lib\Str;
use think\facade\Cache;
use think\Exception;

class Note
{
    public $noteObj = null;

    public function __construct()
    {
        $this->noteObj = new \app\common\model\Note();
    }

    public function note($data)
    {
        return $this->noteObj->note($data);
    }

    public function add_note($data)
    {
        return  $this->noteObj->save($data);
    }

    public function del_note($id)
    {
        return $this->noteObj::destroy($id);
    }

    public function edit_note($data)
    {
        return $this->noteObj::update($data);
    }

    public function one_note($id)
    {
        return $this->noteObj->find($id);
    }

    public function edit_answer($where_data,$answer)
    {
        return $this->answerObj->edit_answer($where_data,$answer);
    }

    public function sign_in_note($ids){
        $sign_in_date = formatTimestamp(time());
        // 根据主键获取多个数据
        $list = $this->noteObj::select($ids);
        // 对数据集进行遍历操作
        foreach($list as $key=>$note){
            $sign_in = [];
           if(!empty($note->sign_in)){
               $sign_in = json_decode($note->sign_in);
           }
           if(!in_array($sign_in_date,$sign_in)){
               $sign_in[] = $sign_in_date;
               $note->sign_in = json_encode($sign_in);
               $note->save();
           }
        }
        return true;
    }
}